package com.szholly.data.coderule.rules;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.szholly.utils.util.StringUtils;
import com.szholly.data.general.*;

/// <summary>
/// 定义时间值编码规则
/// </summary>
@Component("CodeRule_12")
@Scope("prototype")
class DateValueRule extends CodeRuleBase {
	// / <summary>
	// / 获取代码规则值
	// / </summary>
	// / <param name="table">具体表</param>
	// / <param name="entity">要编码的实体</param>
	// / <param name="para">规则生成参数</param>
	// / <returns></returns>
	@Override
	public String GetCodeRule(ITable table, RowBase entity, String para,
			RowBase refEntity, String curCodeRule, String ruleInfoID) {
		
		SimpleDateFormat sdf = null;
		String result = "";
        if (StringUtils.IsNullOrSpace(para)){
        	sdf = new SimpleDateFormat("yyyyMMdd");
        	return result;
        }else{
        	sdf = new SimpleDateFormat(para);
        }
        result = sdf.format(new Date());
        return result;
	}

	// / <summary>
	// / 获取当前是否需要编码规则
	// / </summary>
	// / <param name="table">具体表</param>
	// / <param name="entity">要编码的实体</param>
	// / <param name="para">规则生成参数</param>
	// / <param name="refEntity">参考对象</param>
	// / <param name="fields">字段名集合</param>
	// / <returns></returns>
	@Override
	public Boolean NeedCodeRule(ITable table, RowBase entity, String para,
			RowBase refEntity, String fields) {
		return false;
	}
}
